/**
 * kafka 官方文档地址
 * https://kafka.js.org/docs/getting-started
 * @author xuejianxin
 * @date 2022-12-02
 */
const { Kafka } = require('kafkajs')
const env = process.env.NODE_ENV
let kafkaConfig

if (env === 'dev') {
  // 参考 https://kafka.js.org/docs/configuration
  kafkaConfig = {
    clientId: 'my-app', // A logical identifier of an application.
    brokers: ['localhost:9092']
    // sasl: {
    //  mechanism: 'plain', // scram-sha-256 or scram-sha-512
    //  username: 'my-username',
    //  password: 'my-password'
    // },
  }
} else if (env === 'prod') {
  kafkaConfig = {
    clientId: 'my-app',
    brokers: ['localhost:9092']
  }
}

const kafka = new Kafka(kafkaConfig)

module.exports = {
  kafka
}
